package com.mk.api.sys;

import com.mk.base.model.response.Rsp;
import com.mk.model.request.RoleDirRequest;
import com.mk.service.IRoleDirService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: yq
 * @Description:
 * @Date: Created in 4:41 PM 3/17/18
 */
@RestController
@RequestMapping("/dir/role")
public class DirRoleApi {

    @Autowired
    private IRoleDirService roleDirService;

    @RequestMapping(method = RequestMethod.POST)
    public Rsp changeDirRole(@RequestBody RoleDirRequest request){
        try{
            if(roleDirService.changeRoleDir(request))
                return Rsp.SUCCESS("编辑角色拥有的文件夹权限成功");
            else
                return Rsp.ERROR("编辑角色拥有的文件夹权限失败");
        }catch (Exception e){
            return Rsp.ERROR(e.getMessage());
        }
    }

    @RequestMapping(value = "/{roleId}",method = RequestMethod.GET)
    public Rsp findByRoleId(@PathVariable("roleId")Long roleId){
        try{
            return Rsp.SUCCESS(roleDirService.findByRoleId(roleId));
        }catch (Exception e){
            return Rsp.ERROR(e.getMessage());
        }
    }
}
